//package com.tansun.easycare.rule.front.util;
//
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//
//import org.apache.commons.io.IOUtils;
//import org.apache.hadoop.conf.Configuration;
//import org.apache.hadoop.hbase.HBaseConfiguration;
//import org.apache.hadoop.hbase.TableName;
//import org.apache.hadoop.hbase.client.Admin;
//import org.apache.hadoop.hbase.client.Connection;
//import org.apache.hadoop.hbase.client.ConnectionFactory;
//import org.apache.hadoop.hbase.client.Get;
//import org.apache.hadoop.hbase.client.Result;
//import org.apache.hadoop.hbase.client.Table;
//import org.apache.hadoop.hbase.util.Bytes;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import com.tansun.easycare.rule.front.entity.RuleDatasource;
//
//public class HbaseUtil {
//
//	private static final Logger log = LoggerFactory.getLogger(HbaseUtil.class);
//	
//	private static Map<String,Connection> connMap = new HashMap<String,Connection>();
//    
//    public final static String HBASE_ZOOKEEPER_PORT = "hbase.zookeeper.property.clientPort";
//
//	public static Connection getConnection(RuleDatasource datasource) throws IOException{
//		Connection conn = connMap.get(datasource.getId());
//		if(conn!=null){
//			return conn;
//		}
//		Configuration config = HBaseConfiguration.create();
//		log.debug("hbase url:"+datasource.getDsUrl());
//		log.debug("hbase port:"+datasource.getDsPort());
//		config.set(HBASE_ZOOKEEPER_PORT, datasource.getDsPort());
//		config.set("hbase.zookeeper.quorum", datasource.getDsUrl());
//		conn = ConnectionFactory.createConnection(config);
//		connMap.put(datasource.getId(), conn);
//		return conn;
//	}
//	
//	
//	public static String findColByRowKey(Connection conn,String tbName,String colName,String rowKey) throws IOException{
//		Table table = null;
//		try{
//			String[] ary = colName.split(":");
//			String family = ary[0];
//			String qualifier = ary[1];
//			table = conn.getTable(TableName.valueOf(tbName));
//			Get get = new Get(Bytes.toBytes(rowKey));
//			Result res = table.get(get);
//			if(res.isEmpty()){
//				log.info("行不存在:"+rowKey);
//				return null;
//			}
//			Map<byte[], byte[]> result = res.getFamilyMap(family.getBytes());
//			byte[] val = result.get(qualifier.getBytes());
//			return Bytes.toString(val);
//		}finally{
//			IOUtils.closeQuietly(table);
//		}
//		
//		
//	}
//	
//	public static void main(String[] args) {
//		String []ary = {};
//		System.out.println(ary);
//		Object str = new Object();
//		System.out.println(str);
//	}
//}
